package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @Autowired
    private DishService dishService;

    /**
     * 根据分类id列表展示套餐
     * @param categoryId
     * @return
     */
    @RequestMapping("/list")
    @Cacheable(cacheNames = "setmeal", key = "#categoryId")
    public Result<List<Setmeal>> listSetmealByCategoryId(Long categoryId) {

        List<Setmeal> setmeals = setmealService.selectByCategoryId(categoryId);

        return Result.success(setmeals);
    }


    /**
     * 根据套餐id 查询当前套餐包含的菜品情况
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishBySetmeal(@PathVariable Long id) {

        List<DishItemVO> dishVOS = dishService.selectBySetmealId(id);

        return Result.success(dishVOS);
    }
}
